﻿using System.Collections;
using System.Collections.Generic;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.Web.Security;

using Telerik.Security;

namespace Telerik.Sitefinity.Services.Migration
{
	public partial class MigrationExportService : IMigrationExportService
	{
		public Message GetRoles()
		{
			List<MigrationRole> output = new List<MigrationRole>();

			RoleProviderCollection providers = Roles.Providers;

			foreach (RoleProvider provider in providers)
			{
				string providerName = provider.Name;
				UserManager userManager = new UserManager(providerName);

				IList<RoleInfo> roles = userManager.GetRoles();

				foreach (RoleInfo role in roles)
				{
					MigrationRole mr = new MigrationRole();

					mr.Name = role.Name;

					output.Add(mr);
				}
			}

			MessageVersion ver = OperationContext.Current.IncomingMessageVersion;
			return Message.CreateMessage(ver, "GetRolesResponse", output);
		}
	}
}
